package com.typhoon.spring_shiro.dto;

import java.io.Serializable;

import com.typhoon.spring_shiro.constants.EntityError;

/**
 * 规范化响应dto
 * 
 * @author Typhoon
 *
 * @param <T>
 */
public class ResponseDto<T> extends BaseDto implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -4402179829797126986L;

	/**
	 * 成功标识
	 */
	private static final EntityError SUCCESS = EntityError.S_OK;

	/**
	 * 失败标识
	 */
	private static final EntityError FAIL = EntityError.SYSTEM_ERROR;

	private int code;

	private String msg;

	private T dto;

	public int getCode() {
		return code;
	}

	public String getMsg() {
		return msg;
	}

	public T getDto() {
		return dto;
	}

	public ResponseDto() {
		super();
	}

	public ResponseDto<T> success(T dto) {
		this.code = SUCCESS.getCode();
		this.msg = SUCCESS.getMsg();
		this.dto = dto;
		return this;
	}

	public ResponseDto<T> error(EntityError entityError) {
		entityError = null == entityError ? FAIL : entityError;
		this.code = FAIL.getCode();
		this.msg = FAIL.getMsg();
		return this;
	}

}
